home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / js / jsxml.h < prev   
C/C++ Source or Header  |  2006-05-08  |  10KB  |  329 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is SpiderMonkey E4X code, released August, 2004.
  17.  *
  18.  * The Initial Developer of the Original Code is
  19.  * Netscape Communications Corporation.
  20.  * Portions created by the Initial Developer are Copyright (C) 1998
  21.  * the Initial Developer. All Rights Reserved.
  22.  *
  23.  * Contributor(s):
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  27.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. #ifndef jsxml_h___
  40. #define jsxml_h___
  41.  
  42. #include "jsstddef.h"
  43. #include "jspubtd.h"
  44.  
  45. extern const char js_AnyName_str[];
  46. extern const char js_AttributeName_str[];
  47. extern const char js_isXMLName_str[];
  48. extern const char js_XMLList_str[];
  49.  
  50. extern const char js_amp_entity_str[];
  51. extern const char js_gt_entity_str[];
  52. extern const char js_lt_entity_str[];
  53. extern const char js_quot_entity_str[];
  54.  
  55. struct JSXMLNamespace {
  56.     JSObject            *object;
  57.     JSString            *prefix;
  58.     JSString            *uri;
  59.     JSBool              declared;       /* true if declared in its XML tag */
  60. };
  61.  
  62. extern JSXMLNamespace *
  63. js_NewXMLNamespace(JSContext *cx, JSString *prefix, JSString *uri,
  64.                    JSBool declared);
  65.  
  66. extern void
  67. js_MarkXMLNamespace(JSContext *cx, JSXMLNamespace *ns, void *arg);
  68.  
  69. extern void
  70. js_FinalizeXMLNamespace(JSContext *cx, JSXMLNamespace *ns);
  71.  
  72. extern JSObject *
  73. js_NewXMLNamespaceObject(JSContext *cx, JSString *prefix, JSString *uri,
  74.                          JSBool declared);
  75.  
  76. extern JSObject *
  77. js_GetXMLNamespaceObject(JSContext *cx, JSXMLNamespace *ns);
  78.  
  79. struct JSXMLQName {
  80.     JSObject            *object;
  81.     JSString            *uri;
  82.     JSString            *prefix;
  83.     JSString            *localName;
  84. };
  85.  
  86. extern JSXMLQName *
  87. js_NewXMLQName(JSContext *cx, JSString *uri, JSString *prefix,
  88.                JSString *localName);
  89.  
  90. extern void
  91. js_MarkXMLQName(JSContext *cx, JSXMLQName *qn, void *arg);
  92.  
  93. extern void
  94. js_FinalizeXMLQName(JSContext *cx, JSXMLQName *qn);
  95.  
  96. extern JSObject *
  97. js_NewXMLQNameObject(JSContext *cx, JSString *uri, JSString *prefix,
  98.                      JSString *localName);
  99.  
  100. extern JSObject *
  101. js_GetXMLQNameObject(JSContext *cx, JSXMLQName *qn);
  102.  
  103. extern JSObject *
  104. js_GetAttributeNameObject(JSContext *cx, JSXMLQName *qn);
  105.  
  106. extern JSObject *
  107. js_ConstructXMLQNameObject(JSContext *cx, jsval nsval, jsval lnval);
  108.  
  109. typedef JSBool
  110. (* JS_DLL_CALLBACK JSIdentityOp)(const void *a, const void *b);
  111.  
  112. struct JSXMLArray {
  113.     uint32              length;
  114.     uint32              capacity;
  115.     void                **vector;
  116.     JSXMLArrayCursor    *cursors;
  117. };
  118.  
  119. #define JSXML_PRESET_CAPACITY   JS_BIT(31)
  120. #define JSXML_CAPACITY_MASK     JS_BITMASK(31)
  121. #define JSXML_CAPACITY(array)   ((array)->capacity & JSXML_CAPACITY_MASK)
  122.  
  123. struct JSXMLArrayCursor {
  124.     JSXMLArray          *array;
  125.     uint32              index;
  126.     JSXMLArrayCursor    *next;
  127.     JSXMLArrayCursor    **prevp;
  128. };
  129.  
  130. /*
  131.  * NB: don't reorder this enum without changing all array initializers that
  132.  * depend on it in jsxml.c.
  133.  */ 
  134. typedef enum JSXMLClass {
  135.     JSXML_CLASS_LIST,
  136.     JSXML_CLASS_ELEMENT,
  137.     JSXML_CLASS_ATTRIBUTE,
  138.     JSXML_CLASS_PROCESSING_INSTRUCTION,
  139.     JSXML_CLASS_TEXT,
  140.     JSXML_CLASS_COMMENT,
  141.     JSXML_CLASS_LIMIT
  142. } JSXMLClass;
  143.  
  144. #define JSXML_CLASS_HAS_KIDS(class_)    ((class_) < JSXML_CLASS_ATTRIBUTE)
  145. #define JSXML_CLASS_HAS_VALUE(class_)   ((class_) >= JSXML_CLASS_ATTRIBUTE)
  146. #define JSXML_CLASS_HAS_NAME(class_)                                          \
  147.     ((uintN)((class_) - JSXML_CLASS_ELEMENT) <=                               \
  148.      (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))
  149.  
  150. #ifdef DEBUG_notme
  151. #include "jsclist.h"
  152. #endif
  153.  
  154. struct JSXML {
  155. #ifdef DEBUG_notme
  156.     JSCList             links;
  157.     uint32              serial;
  158. #endif
  159.     JSObject            *object;
  160.     void                *domnode;       /* DOM node if mapped info item */
  161.     JSXML               *parent;
  162.     JSXMLQName          *name;
  163.     uint16              xml_class;      /* discriminates u, below */
  164.     uint16              xml_flags;      /* flags, see below */
  165.     union {
  166.         struct JSXMLListVar {
  167.             JSXMLArray  kids;           /* NB: must come first */
  168.             JSXML       *target;
  169.             JSXMLQName  *targetprop;
  170.         } list;
  171.         struct JSXMLVar {
  172.             JSXMLArray  kids;           /* NB: must come first */
  173.             JSXMLArray  namespaces;
  174.             JSXMLArray  attrs;
  175.         } elem;
  176.         JSString        *value;
  177.     } u;
  178.  
  179.     /* Don't add anything after u -- see js_NewXML for why. */
  180. };
  181.  
  182. /* union member shorthands */
  183. #define xml_kids        u.list.kids
  184. #define xml_target      u.list.target
  185. #define xml_targetprop  u.list.targetprop
  186. #define xml_namespaces  u.elem.namespaces
  187. #define xml_attrs       u.elem.attrs
  188. #define xml_value       u.value
  189.  
  190. /* xml_flags values */
  191. #define XMLF_WHITESPACE_TEXT    0x1
  192.  
  193. /* xml_class-testing macros */
  194. #define JSXML_HAS_KIDS(xml)     JSXML_CLASS_HAS_KIDS((xml)->xml_class)
  195. #define JSXML_HAS_VALUE(xml)    JSXML_CLASS_HAS_VALUE((xml)->xml_class)
  196. #define JSXML_HAS_NAME(xml)     JSXML_CLASS_HAS_NAME((xml)->xml_class)
  197. #define JSXML_LENGTH(xml)       (JSXML_CLASS_HAS_KIDS((xml)->xml_class)       \
  198.                                  ? (xml)->xml_kids.length                     \
  199.                                  : 0)
  200.  
  201. extern JSXML *
  202. js_NewXML(JSContext *cx, JSXMLClass xml_class);
  203.  
  204. extern void
  205. js_MarkXML(JSContext *cx, JSXML *xml, void *arg);
  206.  
  207. extern void
  208. js_FinalizeXML(JSContext *cx, JSXML *xml);
  209.  
  210. extern JSObject *
  211. js_ParseNodeToXMLObject(JSContext *cx, JSParseNode *pn);
  212.  
  213. extern JSObject *
  214. js_NewXMLObject(JSContext *cx, JSXMLClass xml_class);
  215.  
  216. extern JSObject *
  217. js_GetXMLObject(JSContext *cx, JSXML *xml);
  218.  
  219. extern JS_FRIEND_DATA(JSXMLObjectOps)   js_XMLObjectOps;
  220. extern JS_FRIEND_DATA(JSClass)          js_XMLClass;
  221. extern JS_FRIEND_DATA(JSExtendedClass)  js_NamespaceClass;
  222. extern JS_FRIEND_DATA(JSExtendedClass)  js_QNameClass;
  223. extern JS_FRIEND_DATA(JSClass)          js_AttributeNameClass;
  224. extern JS_FRIEND_DATA(JSClass)          js_AnyNameClass;
  225.  
  226. /*
  227.  * Macros to test whether an object or a value is of type "xml" (per typeof).
  228.  * NB: jsapi.h must be included before any call to VALUE_IS_XML.
  229.  */
  230. #define OBJECT_IS_XML(cx,obj)   ((obj)->map->ops == &js_XMLObjectOps.base)
  231. #define VALUE_IS_XML(cx,v)      (!JSVAL_IS_PRIMITIVE(v) &&                    \
  232.                                  OBJECT_IS_XML(cx, JSVAL_TO_OBJECT(v)))
  233.  
  234. extern JSObject *
  235. js_InitNamespaceClass(JSContext *cx, JSObject *obj);
  236.  
  237. extern JSObject *
  238. js_InitQNameClass(JSContext *cx, JSObject *obj);
  239.  
  240. extern JSObject *
  241. js_InitAttributeNameClass(JSContext *cx, JSObject *obj);
  242.  
  243. extern JSObject *
  244. js_InitAnyNameClass(JSContext *cx, JSObject *obj);
  245.  
  246. extern JSObject *
  247. js_InitXMLClass(JSContext *cx, JSObject *obj);
  248.  
  249. extern JSObject *
  250. js_InitXMLClasses(JSContext *cx, JSObject *obj);
  251.  
  252. extern JSBool
  253. js_GetFunctionNamespace(JSContext *cx, jsval *vp);
  254.  
  255. extern JSBool
  256. js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp);
  257.  
  258. extern JSBool
  259. js_SetDefaultXMLNamespace(JSContext *cx, jsval v);
  260.  
  261. /*
  262.  * Return true if v is a XML QName object, or if it converts to a string that
  263.  * contains a valid XML qualified name (one containing no :), false otherwise.
  264.  * NB: This function is an infallible predicate, it hides exceptions.
  265.  */
  266. extern JSBool
  267. js_IsXMLName(JSContext *cx, jsval v);
  268.  
  269. extern JSBool
  270. js_ToAttributeName(JSContext *cx, jsval *vp);
  271.  
  272. extern JSString *
  273. js_EscapeAttributeValue(JSContext *cx, JSString *str);
  274.  
  275. extern JSString *
  276. js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str,
  277.                     JSString *str2);
  278.  
  279. extern JSString *
  280. js_EscapeElementValue(JSContext *cx, JSString *str);
  281.  
  282. extern JSString *
  283. js_ValueToXMLString(JSContext *cx, jsval v);
  284.  
  285. extern JSBool
  286. js_GetAnyName(JSContext *cx, jsval *vp);
  287.  
  288. extern JSBool
  289. js_FindXMLProperty(JSContext *cx, jsval name, JSObject **objp, jsval *namep);
  290.  
  291. extern JSBool
  292. js_GetXMLProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp);
  293.  
  294. extern JSBool
  295. js_SetXMLProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp);
  296.  
  297. extern JSBool
  298. js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
  299.  
  300. extern JSBool
  301. js_DeleteXMLListElements(JSContext *cx, JSObject *listobj);
  302.  
  303. extern JSBool
  304. js_FilterXMLList(JSContext *cx, JSObject *obj, jsbytecode *pc, jsval *vp);
  305.  
  306. extern JSObject *
  307. js_ValueToXMLObject(JSContext *cx, jsval v);
  308.  
  309. extern JSObject *
  310. js_ValueToXMLListObject(JSContext *cx, jsval v);
  311.  
  312. extern JSObject *
  313. js_CloneXMLObject(JSContext *cx, JSObject *obj);
  314.  
  315. extern JSObject *
  316. js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name,
  317.                        JSString *value);
  318.  
  319. extern JSString *
  320. js_MakeXMLCDATAString(JSContext *cx, JSString *str);
  321.  
  322. extern JSString *
  323. js_MakeXMLCommentString(JSContext *cx, JSString *str);
  324.  
  325. extern JSString *
  326. js_MakeXMLPIString(JSContext *cx, JSString *name, JSString *str);
  327.  
  328. #endif /* jsxml_h___ */
  329.